<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group(['namespace'=>'Wechat', 'prefix' => 'wechat', 'middleware' => ['wechat.config','ao']], function (){
    Route::any('/server', 'ServerController@server');
    Route::get('/menu/set', 'ServerController@setMenu');
    Route::get('/js/sdk', 'ServerController@getJsSdk');
    Route::get('/login', 'ServerController@login');
});

Route::group(['namespace'=>'Api', 'prefix' => 'wechat', 'middleware' => ['wechat.config','ao']], function (){
    Route::get('/callback-login', 'UserController@weixinCallback');
});


Route::group(['namespace' => 'Api'], function(){

    Route::options('/{all}', function(Request $request) {
        $origin = $request->header('ORIGIN', '*');
        header("Access-Control-Allow-Origin: $origin");
        header("Access-Control-Allow-Credentials: true");
        header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
        header('Access-Control-Allow-Headers: Origin, Access-Control-Request-Headers, SERVER_NAME, Access-Control-Allow-Headers, cache-control, token, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie');
    })->where(['all' => '([a-zA-Z0-9-]|/)+']);



    Route::group(['middleware' => ['ao','ApiAuth']] , function (){
        //轮播图接口
        Route::get('banner','BannerController@index');
        //贷款申请接口
        Route::post('loanapply','LoanapplyController@doadd');
        //房型数据接口
        Route::post('messageuser','MessageuserController@doadd');
        //新闻接口
        Route::get('news','NewsController@index');
        //指定新闻接口
        Route::get('news/{id}','NewsController@getdata');
        //装修案例接口
        Route::get('examples','ExamplesController@index');
        //詳細案例接口
        Route::get('examples/{id}','ExamplesController@getdata');
        //个人中心接口
        Route::get('personinfo','PersoninfoController@index');
        //合伙人綁定接口
        Route::get('partner','PartnerController@index');
        //vip推广接口
        Route::get('vipuser','VipuserController@index');
        //vip推广第二市场接口
        Route::get('vipusermarket','VipusermarketController@index');
        //vip推广第二市场接口
        Route::get('vipuseradd','VipusermarketController@doadd');
        //二维码接口
        Route::get('qrcode', 'QrcodeController@index');
        //提现记录接口
        Route::get('pointfor/{id}','PointforController@index');
        //提现申请接口
        Route::post('addpointfor','PointforController@doadd');

        //提现记录接口
        Route::get('point','PointController@index');


        //申请测试接口
        Route::post('add','PointforController@add');
        //关于我们接口
        Route::get('linkus','LinkusController@index');

        //房型获取接口
        Route::get('roomdata','RoomdataController@index');
        //授权登录接口
        Route::get('login','LoginwechatController@getbaseinfo');
        //获取openid
        Route::get('openid','LoginwechatController@getopenid');
        //全国地址接口
        Route::get('address','AddressController@index');

        Route::get('addressadd','AddressController@doadd');


        Route::get('index','TestController@test');
        Route::post('test','TestController@index');


    });


});


Route::group(['namespace'=>'Wechat', 'prefix' => 'wechat', 'middleware' => ['ao']], function (){
    Route::any('/server', 'ServerController@server');
    Route::get('/menu/set', 'ServerController@setMenu');
    Route::get('/js/sdk', 'ServerController@getJsSdk');
    Route::get('/login', 'ServerController@login');
});

Route::group(['namespace'=>'Api', 'prefix' => 'wechat', 'middleware' => ['ao']], function (){
    Route::get('/callback-login', 'UserController@weixinCallback');
});


